package com.quanjiaolian.chat.servlet;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.ResourceBundle;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

import com.quanjiaolian.chat.service.ChatService;
import com.quanjiaolian.chat.serviceimpl.ChatServiceImpl;
import com.quanjiaolian.tools.ResponseToJson;

/**
 * 查询所有论坛记录
 * @author Herson_Li
 *
 */
@SuppressWarnings("serial")
public class QueryAllChat extends HttpServlet {
	
	/**
	 * 声明Log4j变量
	 */
	public static ResourceBundle resourceBundle = null;
	static Logger logger = Logger.getLogger(QueryAllChat.class.getName());
	
	Map<String,Object> resultMap = new HashMap<String,Object>();
	List<Object> resultList = new ArrayList<Object>();//返回List
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		this.doPost(request, response);
	}

	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		String firstSize = request.getParameter("firstSize");//起始页
		String maxSize = request.getParameter("maxSize");//返回数据条数
		String user_type = request.getParameter("user_type");//用户类别：0为普通用户，1为健身教练
		String st_id = request.getParameter("st_id");//运动分类ID
		if(firstSize == null || "0".equals(firstSize)){
			firstSize = "1";
		}
		if(maxSize == null){
			maxSize = "5";
		}
		if(st_id == null){
			st_id = "0";
		}
		if(user_type != null){
			ChatService cs = new ChatServiceImpl();
			resultList = cs.queryAllChat(Integer.parseInt(firstSize),Integer.parseInt(maxSize),Integer.parseInt(user_type),Integer.parseInt(st_id));
			if(resultList != null || resultList.size()>0){
				ResponseToJson.responseListOutWithJson(response, resultList);
			}else{
				resultMap.put("result","no more result");
				ResponseToJson.responseOutWithJson(response,resultMap);
			}
		}else{
			resultMap.put("result","Error");
			ResponseToJson.responseOutWithJson(response,resultMap);
		}
	}

}
